#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os, sys, site 
import datetime
import urllib
import urlparse
import re
import math
import codecs

from generator import *

from mako.template import Template
from mako.lookup import TemplateLookup

import web

class View:
    def __init__(self):
        web.header("Content-Type", "text/css; charset=UTF-8")
        web.header("Cache-Control", "no-cache, must-revalidate")
        web.header("Pragma", "no-cache")

    def GET(self,id="index"):

        i = web.input(_method='get')

        if not i.has_key('URL') :
            return web.notfound()

        if not i.has_key('TARGET') :
            return web.notfound()

        target = web.ctx.session.redirect_param 
        param = {}
        for k,v in i.items():
            param[k] = v
        target[i.TARGET] = param
        web.ctx.session.redirect_param = target 
        return web.seeother('http://' + web.ctx.host + '%s' % i.get('URL','') )


    def POST(self,id="index"):
        i = web.input()

        if not i.has_key('URL') :
            return web.notfound()
        if not i.has_key('TARGET') :
            return web.notfound()

        target = web.ctx.session.redirect_param 
        param = {}
        for k,v in i.items():
            param[k] = v
        target[i.TARGET] = param
        web.ctx.session.redirect_param = target 

        return web.seeother('http://' + web.ctx.host + '%s' % i.get('URL','') )

